package com.segersten.othello.model;

import java.io.Serializable;

public class Brick implements Serializable {
	
	private Color color;
	private Point point;
	
	private Brick() {
	}

	
	/**
	 * Play
	 */
	public Brick(Point point,Color color) {
	    assertNotNull(point, "point");
	    assertNotNull(color, "color");
		this.color = color;
		this.point = point;
	}

	public Color getColor() {
		return color;
	}

	public Point getPoint() {
		return point;
	}
	
	public boolean isPass() {
	    return point==null;
	}

	@Override
	public String toString() {
		return "Brick [color=" + color + ", point=" + point + "]";
	}

	@Override
    public int hashCode()
    {
        final int prime = 31;
        int result = 1;
        result = prime * result + ((point == null) ? 0 : point.hashCode());
        return result;
    }

	@Override
    public boolean equals(Object obj)
    {
        if (this == obj)
            return true;
        if (obj == null)
            return false;
        if (getClass() != obj.getClass())
            return false;
        Brick other = (Brick) obj;
        if (point == null)
        {
            if (other.point != null)
                return false;
        } else if (!point.equals(other.point))
            return false;
        return true;
    }

	public String toShortString() {
		return this.color.name()+":"+(this.point==null?"pass":this.point.getX()+":"+this.point.getY());
	}
	
	private void assertNotNull(Object obj, String string)
    {
        if (obj == null)
        {
            throw new NullPointerException("Cannot be null " + string);
        }
    }
	
	
	
}
